In this article we will discuss to convert JSON string to JSON array using JSON.parse () method. After parsing we are using JQurey each() method to loop the Product JSON object get the property values.
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var JSONString = '[{"ProductName":"computer","Code":"ED002","Price":500,"ProductType":"electronic"},{"ProductName":"Chair","Code":"D5695","Price":1500,"ProductType":"furniture"}]';
var productJSON = JSON.parse(JSONString);
var result = '';
$.each(productJSON, function (i, item) {
result += 'Product Name = ' + item.ProductName + '<br/>';
result += 'Code = ' + item.Code+ '<br/>';
result += 'Product Type = ' + item.ProductType + '<br/>';
result += 'Price = ' + item.Price + '<br/><br/>';
});
$('#resultDiv').html(result).css('background-Color', 'rgb(136, 210, 220)');
});
</script>
</head>
<body style="border:1px solid;width:400px">
<div id="resultDiv"></div>
</body>
</html>
Output:
Post your comments / questions
Recent Article
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
Related Article